home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / System 7.0 Samples / CShell⁄THINK C / Help.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-20  |  2.8 KB  |  115 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** Program:        CShell
  5. ** File:        help.c
  6. ** Written by:  Eric Soldan
  7. **
  8. ** Copyright © 1991 Apple Computer, Inc.
  9. ** All rights reserved.
  10. */
  11.  
  12.  
  13.  
  14. /*****************************************************************************/
  15.  
  16.  
  17.  
  18. #include "CShell.h"                /* Get the CShell includes/typedefs, etc.    */
  19. #include "CShellCommon.h"        /* Get the stuff in common with rez.        */
  20. #include "CShell.protos"        /* Get the prototypes for CShell.            */
  21.  
  22. #ifndef __BALLOONS__
  23. #include <balloons.h>
  24. #endif
  25.  
  26. #ifndef __UTILITIES__
  27. #include "Utilities.h"
  28. #endif
  29.  
  30.  
  31.  
  32. /*****************************************************************************/
  33. /*****************************************************************************/
  34.  
  35.  
  36.  
  37. #pragma segment Main
  38. void    DynamicBalloonHelp(void)
  39. {
  40.     WindowPtr        window, oldPort;
  41.     FileRecHndl        frHndl;
  42.     Point            mouseLoc, tip;
  43.     ControlHandle    ctl;
  44.     Rect            rct;
  45.     short            part, message, pos;
  46.     TEHandle        teHndl;
  47.     HMMessageRecord    helpMessage;
  48.     static short    lastMessage;
  49.     static short    position[4] = {5, 6, 2, 1};
  50.  
  51.     if (gSystemVersion < 0x0700) return;
  52.         /* The system can't support balloons. */
  53.  
  54.     if ((!HMGetBalloons()) || (!IsAppWindow(FrontWindow()))) {
  55.         lastMessage = 0;
  56.         return;
  57.     }        /* Balloons have been turned off, or it isn't our window anymore. */
  58.  
  59.     HMGetBalloonWindow(&window);
  60.     if (!window) lastMessage = 0;
  61.         /* There is no balloon currently, so there is no last message. */
  62.  
  63.     tip = mouseLoc = GetGlobalMouse();
  64.     part = FindWindow(mouseLoc, &window);
  65.     if ((window != FrontWindow()) || (part != inContent)) {
  66.         lastMessage = 0;
  67.         return;
  68.     }        /* We aren't over the content of the front window, so leave. */
  69.  
  70.     GetPort(&oldPort);
  71.     frHndl = (FileRecHndl)GetWRefCon(window);
  72.     SetPort(window);
  73.     GlobalToLocal(&mouseLoc);
  74.  
  75.     ctl = ((WindowPeek)window)->controlList;
  76.     while (ctl) {
  77.         rct = (*ctl)->contrlRect;
  78.         if (PtInRect(mouseLoc, &rct)) break;
  79.         ctl = (*ctl)->nextControl;
  80.     }        /* Find the control that we are over. */
  81.  
  82.     message = 0;
  83.     if (ctl) {
  84.         teHndl = (TEHandle)GetCRefCon(ctl);
  85.         if (teHndl == (*frHndl)->doc.inBox)  message = 2;
  86.         if (teHndl == (*frHndl)->doc.outBox) message = 4;
  87.     }
  88.  
  89.     if (message) {
  90.         if ((*frHndl)->doc.connected) --message;
  91.         if (lastMessage != message) {    /* If this balloon isn't current balloon... */
  92.             lastMessage = message;
  93.             helpMessage.hmmHelpType             = khmmStringRes;
  94.             helpMessage.u.hmmStringRes.hmmResID = rDynHelpStrings;
  95.             helpMessage.u.hmmStringRes.hmmIndex = message;
  96.             LocalToGlobalRect(&rct);
  97.             pos = (tip.v > (rct.top + rct.bottom) / 2) ? 2 : 0;
  98.             if (tip.h > (rct.left + rct.right) / 2) ++pos;
  99.             pos = position[pos];
  100.             SetOrigin(0, 0);
  101.             HMShowBalloon(&helpMessage, tip, &rct, nil, 0, pos, kHMRegularWindow);
  102.         }
  103.     }
  104.     else {
  105.         if (lastMessage) HMRemoveBalloon();
  106.         lastMessage = 0;
  107.     }
  108.  
  109.     SetOrigin(0, 0);
  110.     SetPort(oldPort);
  111. }
  112.  
  113.  
  114.  
  115.